/**
 * 
 */
package com.apache.website.service.plugins;

import java.util.List;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.database.model.Page;
import com.apache.tools.ClassToolsUtil;
import com.apache.website.entity.Manuscript;
import com.apache.website.manager.ManuscriptManager;

/**
 * @author dyhou
 *
 */
public class ManuscriptListPluginImpl implements PluginConnector {

	private ManuscriptManager manuscriptManager;

	/* (non-Javadoc)
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)
	 */
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		ParamsVo<Manuscript> vo = new ParamsVo<Manuscript>();
		Manuscript mt = new Manuscript();
		mt = (Manuscript) ClassToolsUtil.getInstance().convert2Bean(param.getParams(), mt);
		vo.setObj(mt);
		vo.setKey(String.valueOf(param.getParams("orderBy")));
		int pageSize = Integer.valueOf(Validator.getDefaultStr(String.valueOf(param.getParams("pageSize")), "0"));
		int pageIndex = Integer.valueOf(Validator.getDefaultStr(String.valueOf(param.getParams("pageIndex")), "0"));
		if (pageSize == 0 && pageIndex == 0) {
			List<Manuscript> list = manuscriptManager.getList(vo);
			entity.setEntity(list);
		} else {
			vo.setParams("pageIndex", pageIndex);
			vo.setParams("pageSize", pageSize);
			Page page = manuscriptManager.getPageInfo(vo);
			entity.setEntity(page);
		}
		entity.setResult("true");
		entity.setMessage("查询成功");
		return entity;
	}

	public void setManuscriptManager(ManuscriptManager manuscriptManager) {
		this.manuscriptManager = manuscriptManager;
	}

}
